class Gcs_Nithor : Gcs_Shopkeeper {
	Default {
		+FLOATBOB
		
		Gcs_Shopkeeper.ViewDistance 80;
		Gcs_Shopkeeper.Zoffset -5;
		FloatBobStrength 0.11337;
		RenderStyle "None";
		Alpha 0.9;
		Scale 0.2666;
		
		Gcs_Shopkeeper.NameKey			"shopkeeper_nithor";
		Gcs_Shopkeeper.TalkStartColor   Font.CR_BLACK;
		Gcs_Shopkeeper.TalkFinalColor   Font.CR_DARKRED;
		Gcs_Shopkeeper.ConsoleColor		"\c[darkred]";
		Gcs_Shopkeeper.CanMessage		true;
		Gcs_Shopkeeper.Icon				"shpknith";
	}
	
	double grow_scale;
	int shake_count;
	
	States {
	
	// Frames:
	// a 0 - Neutral
	// b 1 - Blink
	// c 2 - Looks to his left
	// d 3 - To his right
	// e 4 - Taps knee
	// f 5 - Raises tail
	// g 6 - Thumbs up
	// i 8 - Really happy thumbs up
	// j 9 - Slightly dismayed
	// k 10 - Upset
	// l 11 - Angry
	// m 12 - WRATH
	// n 13 - Horse grin
	
	Spawn:
		NITH A 4; // nodelay doesn't work.
		
		NITH A 0 {
			A_SpawnItemEx("Gcs_NithorAura", flags: SXF_SETTARGET);
			A_SpawnItemEx("GC_NithorAppears", zofs: 10);
			grow_scale = scale.x;
			scale = (0, 0);
			
			A_SetRenderStyle(alpha, STYLE_TRANSLUCENT);
			
			let mo = Guncaster(user_mo);
			
			if(mo && mo.user_carlton) {
				frame = 10;
			}
			
			else {
				frame = 13;
			}
		}
		
	Appears:
		"####" "#" 1 {
			A_SetScale(scale.x + 0.01333);
			if(grow_scale <= scale.x) {
				A_SetScale(grow_scale);
				SetStateLabel("WelcomingStay");
			}
		}
		Wait;
	
	
	WelcomingStay:
		"####" "#" 45;
		goto IdleBegin;
	
	IdleBegin:
		NITH A 0 {
			let mo = Guncaster(user_mo);
			
			if(mo && mo.user_carlton) {
				SetStateLabel("IdleCarlton");
			}
			
			else {
				SetStateLabel("IdleNormal");
			}
		}
		goto IdleNormal;
	
	IdleCarlton:
		NITH N 350;
		goto AnyActionWillDo;
	
	IdleNormal:
		NITH A random(200, 400) {
			if(3 < idle_counter) {
				frame = 10;
			}
		}
		
		goto AnyActionWillDo;
	
	AnyActionWillDo:
        NITH A 2 A_Jump(100, "Blink");
        NITH A 2 A_Jump(60, "TapKnee");
        Goto LookAround;
    Blink:
        NITH B 4;
        NITH A 4;
        NITH A 4 A_Jump(180, "BlinkAgain");
        Goto IdleNormal;
    BlinkAgain:
        NITH B 4;
        NITH A 4;
        NITH A 4 A_Jump(40, "BlinkAgain");
        Goto IdleNormal;
    
    TapKnee:
        NITH AEAEAE 7;
        NITH E 10 A_Jump(180, "Blink");
        Goto IdleNormal;
    LookAround:
        NITH C 30;
        NITH A 5;
        NITH D 30;
        NITH A 5 A_Jump(180, "TapKnee");
        Goto IdleNormal;
	
	React:
		NITH A 0 {
			if(idle_counter < 2) {
				SetStateLabel("NormalReaction");
			}
			
			else if(idle_counter < 4) {
				SetStateLabel("BadReaction");
			}
			
			else {
				SetStateLabel("WorstReaction");
			}
		}
	
	NormalReaction:
		NITH A 0 A_Jump(256, "LookSide", "CloseEyes", "Sneer");
		goto IdleBegin;
	
	BadReaction:
		NITH A 0 A_Jump(256, "CountToTen", "ImpatientTap", "Impatient");
		goto IdleBegin;
	
	WorstReaction:
		NITH A 0 A_Jump(256, "Angry");
		goto IdleBegin;
	
	CloseEyes:
		NITH A 5;
		NITH B 50;
		goto IdleBegin;
	
	LookSide:
		NITH C 70 {
			frame = random(0, 1) == 0 ? 3 : 4;
		}
		NITH A 20;
		goto IdleBegin;
	
	ImpatientTap:
		NITH A 6;
		NITH E 3;
		NITH A 6;
		NITH E 3;
		NITH A 6;
		NITH E 3;
		NITH A 6;
		NITH E 8;
		NITH A 20;
		goto IdleBegin;
	
	CountToTen:
		NITH K 15 {
			shake_count = 60;
		}
		
	CountLoop:
		NITH K 1 {
			vel = (frandom(-1, 1), frandom(-1, 1), 0);
			
			shake_count--;
			
			if(shake_count == 40) {
				A_Quake(1, 40, 0, 400);
			}
			
			if(shake_count <= 0) {
				SetStateLabel("CountEnd");
			}
		}
		
		loop;
	
	CountEnd:
		NITH K 20;
		NITH BA 10;
		goto IdleBegin;
	
	thumbsup:
		NITH G 80;
		goto IdleBegin;
	
	happythumbsup:
		NITH I 80;
		goto IdleBegin;
	
	sneer:
		NITH N 80;
		goto IdleBegin;
	
	worried:
		NITH J 80;
		goto IdleBegin;
	
	impatient:
		NITH K 80;
		goto IdleBegin;
	
	angry:
		NITH L 5 {
			shake_count = random(80, 110);
		}
	
	angry_shake:
		NITH L 1 {
			vel = 0.25 * (random(-2, 2), random(-2, 2), 0);
			
			shake_count--;
			
			if(shake_count == 60) {
				A_Quake(1, 3 * shake_count / 4, 0, 400);
			}
			
			else if(shake_count <= 0) {
				SetStateLabel("angry_end");
			}
		}
		
		loop;
	
	angry_end:
		NITH K 25 {
			vel = (0, 0, 0);
		}
		
		goto idlebegin;
	
	ITSGODDAMNEXTREMESPHEREBURNINGTIME:
		NITH M 150 {
			bool    spawn_ok;
			Actor   spawn_fire;
			
			for(int i = -2; i <= 2; i++) {
				[spawn_ok, spawn_fire] =
					A_SpawnItemEx("GC_NithorAgitationFire", zofs: 10);
				
				if(spawn_fire) {
					spawn_fire.roll = i * 30;
				}
			}
		}
		
		goto IdleBegin;
        
    ByeBye:
        NITH G 20 {
			frame = 3 < idle_counter ? 12 : 6;
		}
		
        NITH "#" 4 A_SpawnItemEx("GC_NithorAppears", zofs: 10);
        Stop;
        
    IdiotByeBye:
        NITH K 20;
        NITH K 4 A_SpawnItemEx("GC_NithorAppears", zofs: 10);
        Stop;
	}
	
	override void OnRemove () {
		super.OnRemove();
		
		A_SetScale(grow_scale);
		
		if(user_mo && user_mo.health < 1) {
			SetStateLabel("IdiotByeBye");
			SpeakRandom("nithor_youdied", 1, 5);
		}
		
		else if(random(0, 1) == 0) {
			SetStateLabel("ByeBye");
			SpeakRandom("nithor_byebye", 1, 9);
		}
		
		else {
			SetStateLabel("ByeBye");
			SpeakRandom("nithor_leaving", 1, 8);
		}
		
		may_talk = false;
	}
	
	void SpeakRandom (String lang_key, uint low, uint high) {
		String msg, sound;
		
		[msg, sound] = MsgAndVoice(lang_key, random(low, high));
		A_PlaySound(sound);
		
		if(customer.mo && consoleplayer == customer.mo.PlayerNumber()) {
			ConsoleSpeak(msg);
		}
	}
	
	override void PostBeginPlay () {
		may_talk = false;
		
		if(!shop) {
			return;
		}
		
		String msg, sound;
		
		if(!!Guncaster(user_mo).user_carlton) {
			BoxSpeakVoice("nithor_carlton", random(1, 7));
		}
		
		else {
			if(random(0, 2) == 0) {
				BoxSpeakVoice("nithor_welcome", random(1, 4));
			}
			
			else {
				BoxSpeakVoice("nithor_hello", random(1, 11));
			}
		}
		
		idle_counter = 0;
		talk_timer = 35 * random(20, 25);
		may_talk = true;
	}
	
	// This runs immediately after spawn, it seems like, so for our intentions,
	// it's not very useful.
	/* override void PostBeginPlay () {
	}*/
	
	/*
	
		EVENT_NONE = 0,
		EVENT_BUY_FREEBIE,
		EVENT_BUY_OKAY,
		EVENT_BUY_POOR,
		EVENT_BUY_MAXED,
		EVENT_BUY_WORSE,
		EVENT_BUY_OKAY_BUT_WORSE,
		EVENT_BUY_CANT_CARRY,
		EVENT_EQUIP_OKAY_ON,
		EVENT_EQUIP_OKAY_OFF,
		EVENT_EQUIP_DONT_HAVE,
		EVENT_EQUIP_CANT,
		EVENT_EQUIP_ALREADY,
		EVENT_EQUIP_NOT_YET,
		EVENT_BAD_HANDLER,
		EVENT_BAD_CHOICE,
		EVENT_NO_USER
	
	*/
	
	override void OnBuy (int result, uint shop_i, uint item_i) {
		String msg, sound;
		
		switch(result) {
		case Gc_Shop_Inv.EVENT_BUY_OKAY:
		case Gc_Shop_Inv.EVENT_BUY_OKAY_BUT_WORSE:
			
			// Let's check the item.
			let inv = ItemClass(shop_i, item_i);
			
			if(inv is 'EXTREMESPHERE') {
				SetStateLabel("ITSGODDAMNEXTREMESPHEREBURNINGTIME");
				BoxSpeakVoice("nithor_xsphere", random(1, 11));
			}
			
			else {
				
				if(ItemCost(shop_i, item_i) < 2000) {
					SetStateLabel("ThumbsUp");
				}
				
				else {
					SetStateLabel("HappyThumbsUp");
				}
				
				BoxSpeakVoice("nithor_buy", random(1, 21));
			}
			
			talk_timer = 35 * random(25, 30);
			idle_counter = 0;
			break;
		
		case Gc_Shop_Inv.EVENT_BUY_POOR:
			SetStateLabel("React");
			BoxSpeakVoice("nithor_poor", random(1, 13));
			talk_timer = 35 * random(15, 20);
			break;
		
		case Gc_Shop_Inv.EVENT_BUY_MAXED:
		case Gc_Shop_Inv.EVENT_BUY_CANT_CARRY:
			SetStateLabel("React");
			BoxSpeakVoice("nithor_limit", random(1, 8));
			talk_timer = 35 * random(15, 20);
			break;
		}
	}
	
	int talk_timer;
	int idle_counter;
	bool may_talk;
	
	override void Tick () {
		super.Tick();
		
		if(may_talk) {
			if(talk_timer-- <= 0) {
				
				if(Guncaster(user_mo).user_carlton && random(0, 2) < 2) {
					SetStateLabel("worried");
					BoxSpeakVoice("nithor_carlton", random(1, 7));
					idle_counter += 2;
					talk_timer = 35 * random(15, 20);
				}
				
				// Not that bored yet.
				else if(idle_counter < 4) {
					SetStateLabel("React");
					BoxSpeakVoice("nithor_idle", random(1, 13));
					idle_counter++;
					talk_timer = 35 * random(20, 25);
				}
				
				// Ugh!
				else {
					SetStateLabel("React");
					BoxSpeakVoice("nithor_bored", random(1, 13));
					talk_timer = 35 * random(20, 25);
				}
				
			}
		}
	}
	
	override void OnEquip (int result, uint shop_i, uint item_i) {
		switch(result) {
		case Gc_Shop_Inv.EVENT_EQUIP_DONT_HAVE:
		case Gc_Shop_Inv.EVENT_EQUIP_CANT:
		case Gc_Shop_Inv.EVENT_EQUIP_NOT_YET:
			BoxSpeakVoice("nithor_cant", 1);
			talk_timer = (talk_timer / 350 + 1) * 350;
			break;
		}
	}
}

class GC_NithorAppears : Actor {
    Default {
        +NOINTERACTION
		+DONTSPLASH
		+DONTBLAST
		+NOTIMEFREEZE
		
        Scale 1.1;
        RenderStyle "Add";
        Alpha 0.99;
    }

    States {
    Spawn:
        TNT1 A 35 NoDelay {
			A_PlaySound("Matriarch/Exp",6); //Must be a soundslot, else it cuts off when disappears, lol?
			A_PlaySound("Nithor/Poof",5,0.7);
			A_QuakeEx(4,1,1,25,0,128,"none",QF_SCALEDOWN);
			A_SpawnItemEx("GC_NithorPoof",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
		}
        //MISL BCD 5;
        Stop;
    }
}

class GC_NithorAura : Actor {
    Default {
        +NOINTERACTION
		+DONTSPLASH
		+NOTIMEFREEZE
		+DONTBLAST
    }

    int alive_tics;
    int spawn_tics;
    int streak_angle;

    States {

    Spawn:
        TNT1 A 1 {
            if(target == null || GetCvar("GC_ToasterMode")) {
                Destroy();
                return;
            }

            SetOrigin(target.pos, false);

            alive_tics++;
            spawn_tics++;
            if(7 <= spawn_tics) {
                actor streak, blur;

                // kd:
                // CHANG'E, ARE YOU WATCHING?

                vector3 spawn_pos = pos + AngleToVector(angle, 16);
                streak = Spawn("GC_NithorAuraStreak", spawn_pos);
                spawn_tics = 0;

                if(streak != null) {
                    streak.roll = -60.0f + 30.0f * streak_angle;
                    streak.special1 = alive_tics + streak_angle * 120;
                    streak_angle++;

                    // kd:
                    // this kinda overdoes it lol

                    /* if(streak_angle % 2 == 0) {
                        blur = Spawn("NithorAuraBlur", spawn_pos);

                        if(blur != null) {
                            blur.special1 = alive_tics + 300;
                        }
                    } */
                }

                if(5 <= streak_angle) {
                    streak_angle = 0;
                }
            }
        }

        Loop;
    
    Death:
        Stop;
    }

}

class GC_NithorAuraBlur : GC_NithorAuraStreak {
    Default {
        Scale 0.2666;
    }

    States {
    Spawn:
        NITH A 1 Bright {
            double fade = GC_PulseFunc.la_pulsef(1.0 * alive_tics / 160);

            alive_tics++;

            alpha = fade / 12;
            scale.x = 0.25 + fade / 9;
            scale.y = 0.25 + fade / 7;

            if(160 < alive_tics) {
                Destroy();
            }
        }

        Loop;
    }
}

class GC_NithorAuraStreak : Actor {
    Default {
        +NOINTERACTION
        +ROLLSPRITE
        +FORCEYBILLBOARD
		+DONTSPLASH
		+DONTBLAST
		+NOTIMEFREEZE

        RenderStyle "AddShaded";
        StencilColor "ff5020";
        Alpha 0;
    }
	
	private int hor_scale_sign;
    int alive_tics;
    double scaling_f;

    override void PostBeginPlay (void) {
		hor_scale_sign = RandomPick(-1, 1);
        int r1 = 255, g1 = 20, b1 = 10;
        int r2 = 0, g2 = 0, b2 = 0;

        alive_tics = 0;
        scaling_f = FRandom(0.420, 0.666) * 0.777;

        scale.x = hor_scale_sign * 0.6 * scaling_f;
        scale.y = scaling_f;

        int tics = special1 % 600;
        int r, g, b;
        
        if(tics < 300) {
            r = r1 + (r2 - r1) * tics / 300;
            g = g1 + (g2 - g1) * tics / 300;
            b = b1 + (b2 - b1) * tics / 300;
        }

        else {
            tics -= 300;
            r = r2 + (r1 - r2) * tics / 300;
            g = g2 + (g1 - g2) * tics / 300;
            b = b2 + (b1 - b2) * tics / 300;
        }
		
        Color stencil_color = Color(r, g, b);
        SetShade(stencil_color);
		if(r <= 128) { A_SetRenderstyle(alpha,STYLE_Shaded); }
    }

    States {
    Spawn:
        FLAM E 1 Bright { //FIRE D
            alive_tics++;
            alpha = GC_PulseFunc.la_pulsef(1.0 * alive_tics / 120) / 3;
            scale.x += hor_scale_sign * FRandom(0.0005, 0.0008) * scaling_f;
            scale.y +=                  FRandom(0.005,  0.0088) * scaling_f;

            if(120 < alive_tics) {
                Destroy();
            }
        }

        Loop;
    }
}

class GC_NithorAgitationFire : Actor {
    Default {
        +NOINTERACTION
		+NOTIMEFREEZE

        Radius 0;
        Height 0;
    }

    int lifetime;

    override void PostBeginPlay (void) {
        lifetime = 99;
    }

    States {
    Spawn:
        TNT1 A 1 {
            Actor flame;

            flame = Spawn("GC_NithorExtremeFlame", pos);

            if(flame != null) {
                flame.special1 = lifetime;
                flame.roll     = roll;

                if(lifetime-- <= 0) {
                    Destroy();
                }
            }
        }

        Wait;
    }
}

class GC_NithorExtremeFlame : GC_NithorAuraStreak {
    Default {
        Alpha 0.81337;
    }

    override void PostBeginPlay (void) {
        int r1 = 240, g1 = 90,  b1 = 30;
        int r2 = 90, g2 = 150, b2 = 240;

        alive_tics = 0;
        scaling_f = FRandom(0.2420, 0.666) * 1.337 * (special1 + 40) / 80;

        scale.x =
            0.5 * RandomPick(-1, 1) * FRandom(0.8, 1.3) *
            (special1 + 40) / 80;
        scale.y = scaling_f;

        int tics = special1 % 100;
        int r, g, b;
        
        r = r1 + (r2 - r1) * tics / 100;
        g = g1 + (g2 - g1) * tics / 100;
        b = b1 + (b2 - b1) * tics / 100;

        Color stencil_color = Color(r, g, b);
        SetShade(stencil_color);
    }

    States {
    Spawn:
        FLAM E 1 Bright {
            alive_tics++;
            scale.y += FRandom(0.1111, 0.1337) * scaling_f;
            // scale.x -= FRandom(0.01, 0.0222) * scaling_f;
            alpha    = 1.0 - (12 - alive_tics) / 12;

            if(12 < alive_tics) {
                Destroy();
            }
        }

        Loop;
    }
}

//Hav no feer, Pillow wuz hier~
class GC_NithorPoofBase : Actor
{
    Default
	{
        +NOINTERACTION
		+DONTSPLASH
		+DONTBLAST
		+NOTIMEFREEZE
    }
}

class GC_NithorPoof : GC_NithorPoofBase //GC_NithorPoof
{
	int count;
	int timer;

	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			timer = 15;
			A_SpawnItemEx("GC_NithorFlare",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
			A_SpawnItemEx("GC_NithorFlash",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
			for(count = 0; count < 30; count++) {
				A_SpawnItemEx("GC_NithorCloud",0,0,0,
					frandom(2.0,0.1),0,frandom(2.0,0.1) * frandom(1,-1),
					frandom(0.0,360.0),SXF_CLIENTSIDE);
			}
			for(count = 0; count < 140; count++) {
				A_SpawnItemEx("GC_NithorParticle",0,0,0,
					frandom(4.0,0.5),0,frandom(4.0,0.5) * frandom(1,-1),
					frandom(0.0,360.0),SXF_CLIENTSIDE);
			}	
		}
		TNT1 A 12;
		TNT1 A 1 {
			A_SetAngle(frandom(0.0,360.0)); //CIRCLE THE CUBE, VITRUVIAN MEISTER~
			A_SpawnItemEx("GC_NithorLightning",frandom(32.0,-32.0),
				frandom(32.0,-32.0),frandom(32.0,-32.0),
				0,0,0,0,SXF_CLIENTSIDE);
			timer--;
			Return A_JumpIf(timer <= 0, "Null");
		}
		wait;
	}
}

class GC_NithorFlare : GC_NithorPoofBase
{
	Default
	{
		Alpha 1.0;
		Scale 1.5;
		Renderstyle "AddShaded";
		StencilColor "ff2005";
	}
	
	States
	{
	Spawn:
		FLER A 1 Bright NoDelay {
			A_SetScale(Scale.X * 0.98);
			A_FadeOut(0.03);
			Return A_JumpIf(Scale.X <= 0, "Null");
		}
		Loop;
	}
}

class GC_NithorFlash : GC_NithorFlare
{
	Default
	{
		Alpha 0.4;
		Scale 3.0;
	}
	
	States
	{
	Spawn:
		FLER A 1 Bright NoDelay {
			A_SetScale(Scale.X - 0.02);
			A_FadeOut(0.02);
			Return A_JumpIf(Scale.X <= 0, "Null");
		}
		Loop;
	}
}

class GC_NithorCloud : GC_NithorPoofBase
{
	Default
	{
		Alpha 0.0;
		Scale 0.0;
		Renderstyle "AddShaded";
		StencilColor "ff0000";
		+ROLLSPRITE
		+ROLLCENTER
	}
	
	bool IsRedNow;
	int r;
	int g;
	int b;
	
	States
	{
	Spawn:
		TNT1 A random(0,6);
		CLOD A 0 {
			A_SetScale(Scale.X + frandom(0.15,0.25));
			A_SetRoll(frandom(0.0,360.0));
			//A_FadeIn(frandom(0.9,0.99));
			Return A_Jump(256,"SetupA","SetupB");
		}
	SetupA:
		"####" "#" 0 {
			IsRedNow = 1;
			r = random(30,235);
			g = random(20,0);
			g = random(5,0);
			SetShade(color(r,g,b));
			Return ResolveState("Main");
		}
		Goto Main;
	SetupB:
		"####" "#" 0 {
			IsRedNow = 0; //I probably don't wanna leave it undefined.
			A_SetRenderStyle(Alpha, STYLE_Shaded);
			SetShade("000000");
			Return ResolveState("Main");
		}
		Goto Main;
	Main:
		CLOD A 1 Bright {
			A_ScaleVelocity(0.98);
			A_SetScale(Scale.X + 0.1);
			A_FadeIn(0.11);
			Return A_JumpIf(Alpha >= 0.99 || (IsRedNow && Alpha >= 0.77), "Main2");
		}
		Loop;
	Main2:
		CLOD A 1 Bright {
			A_ScaleVelocity(0.98);
			A_SetScale(Scale.X * 0.98);
			A_FadeOut(0.025);
			Return A_JumpIf(Scale.X <= 0.005, "Null");
		}
		Loop;
	}
}

class GC_NithorLightning : GC_NithorCloud
{
	Default
	{
		Alpha 0.0;
		Scale 0.0;
		Renderstyle "AddShaded";
		StencilColor "ff0000";
	}
	
	States
	{
	Spawn:
		RLIT A 0 NoDelay {
			A_SetScale(Scale.X + frandom(0.2,0.35));
			A_FadeIn(frandom(0.9,0.99));
			A_SetRoll(frandom(0.0,360.0));
			Return A_Jump(128,"SpriteE");
		}
		Goto Setup;
	SpriteE:
		RLIT E 0;
		Goto Setup;
	Setup:
		"####" "#" 0 A_Jump(256,"SetupA","SetupB");
	Main:
		"####" "#" 1 Bright A_FadeOut(0.1);
		Loop;
	}
}


class GC_NithorParticle : GC_NithorCloud
{
	Default
	{
		-ROLLSPRITE
		-ROLLCENTER
	}
	
	States
	{
	Spawn:
		TNT1 A random(3,6);
		RPRT A 0 {
			A_SetScale(Scale.X + frandom(0.025,0.05));
			A_FadeIn(frandom(0.9,0.99));
			Return A_Jump(256,"SetupA","SetupB");
		}
	Main:
		RPRT A 1 Bright {
			//A_ScaleVelocity(0.98);
			A_ChangeVelocity(frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(0.0,-0.2),CVF_RELATIVE);
			A_SetScale(Scale.X * 0.95);
			A_FadeOut(0.025);
			Return A_JumpIf(Scale.X <= 0.005, "Null");
		}
		Loop;
	}
}

class Gcs_NithorAura : Actor {
    Default {
        +NOINTERACTION
		+DONTSPLASH
		+NOTIMEFREEZE
		+DONTBLAST
    }

	const aura_dist = 30;
	vector3 offset;
	bool stuck;
	
	override void PostBeginPlay () {
		if(target) {
			offset.xy	= AngleToVector(target.angle, -aura_dist);
			offset.z	= 0;
			stuck		= true;
		}
		
		else {
			stuck = false;
		}
	}

    States {
    Spawn:
        TNT1 A 12 {
			// CHANG'E, ARE YOU WATCHING?
			bool	spawn_ok;
			Actor	mo;
			
			[spawn_ok, mo] = A_SpawnItemEx("Gcs_NithorAuraStreak");
			
			if(!spawn_ok || !mo) {
				return;
			}
			
			// And stick please.
			if(target) {
				SetOrigin(target.pos + offset, false);
			}
			
			else if(stuck) {
				Destroy();
			}
		}
        Loop;
    }

}

class Gcs_NithorAuraStreak : Actor {
    Default {
        +NOINTERACTION
        +ROLLSPRITE
        +FORCEYBILLBOARD
		+DONTSPLASH
		+DONTBLAST
		+NOTIMEFREEZE

        RenderStyle "AddShaded";
        StencilColor "ff5020";
        Alpha 0;
    }
	
	private int hor_scale_sign;
    int alive_tics;
    double scaling_f;
	
	const color_tics	= 600;
	const color_tics_2	= color_tics / 2;

    override void PostBeginPlay (void) {
		hor_scale_sign = RandomPick(-1, 1);
        int r1 = 255,	g1 = 20,	b1 = 10;
        int r2 = 0,		g2 = 0,		b2 = 0;

        alive_tics = 0;
        scaling_f = FRandom(0.420, 0.666) * 0.666;

        scale.x = hor_scale_sign * 0.6 * scaling_f;
        scale.y = scaling_f;

        int tics = level.time % color_tics;
        int r, g, b;
        
        if(tics < color_tics_2) {
            r = r1 + (r2 - r1) * tics / color_tics_2;
            g = g1 + (g2 - g1) * tics / color_tics_2;
            b = b1 + (b2 - b1) * tics / color_tics_2;
        }

        else {
            tics -= color_tics_2;
            r = r2 + (r1 - r2) * tics / color_tics_2;
            g = g2 + (g1 - g2) * tics / color_tics_2;
            b = b2 + (b1 - b2) * tics / color_tics_2;
        }
		
        Color stencil_color = Color(r, g, b);
        SetShade(stencil_color);
		if(r <= 128) { A_SetRenderstyle(alpha,STYLE_Shaded); }
		
		roll = -60 + (level.time % 5) * 30;
    }

    States {
    Spawn:
	FadeIn:
        FLAM E 1 Bright {
			A_FadeIn(0.0025);
			
            scale.x += hor_scale_sign * FRandom(0.0005, 0.0008) * scaling_f;
            scale.y +=                  FRandom(0.005,  0.0088) * scaling_f;

            if(0.4 < alpha) {
                SetStateLabel("FadeOut");
            }
        }

        Loop;
	FadeOut:
        FLAM E 1 Bright {
			A_FadeOut(0.0025);
			
            scale.x += hor_scale_sign * FRandom(0.0005, 0.0008) * scaling_f;
            scale.y +=                  FRandom(0.005,  0.0088) * scaling_f;
        }

        Loop;
    }
}